package com.weixing.mall.core.utils;

import cn.hutool.core.util.StrUtil;
import jodd.util.RandomString;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.UUID;

/**
 * @Author: kfc
 * @Description: <br/>
 * Date:Create in 2019/5/30 15:14
 * @Modified By:
 */
public class CommonUtil {

    /**
     * 随机生成验证码
     * @param n
     * @return
     */
    public static String genVerifyCode(int n){
        return RandomString.getInstance().randomNumeric(n);
    }

    /**
     * 生成UUID
     *
     * @return
     */
    public static String fmtUuid(){
       return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 密码加密
     *
     * @param password
     * @return
     */
    public static String encryptPassword(String password){
        return new BCryptPasswordEncoder().encode(password);
    }

    /**
     * 方法描述: 校验密文
     * @Author Small
     * @param rawStr
     * @param encryptStr
     * @Date 2019/11/14 10:59
     * @return boolean
    */
    public static boolean bCryptCheck(String rawStr, String encryptStr){
        return new BCryptPasswordEncoder().matches(rawStr,encryptStr);
    }


    /**
     * 方法描述: 隐藏姓名
     * @Author Small
     * @param realName
     * @Date 2020/3/10 15:41
     * @return java.lang.String
     */
    public static String coverRealName(String realName){
        return  StrUtil.replace(realName,1,realName.length() , '*');
    }

    /**
     * 方法描述:隐藏手机号
     * @Author Small
     * @param mobile
     * @Date 2020/3/10 15:48
     * @return java.lang.String
    */
    public static String coverMobile(String mobile){
        return  StrUtil.replace(mobile,3,mobile.length()-4 , '*');
    }


    public static void main(String[] args) {


        boolean b = bCryptCheck("jagns2020", "$10$YCWX/Q2IWuYGJLwkpjCqfuLbwZjRF6qFGN.cu90v6HdBrj.0lkc/W");
        System.out.println(b);


        System.out.println(encryptPassword("1234qwer"));

    }

}
